package com.itheima.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.itheima.bean.DishFlavor;
import com.itheima.dao.DishFlavorDao;
import com.itheima.service.DishFlavorService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
@Transactional
public class DishFlavorServiceImpl implements DishFlavorService {
    @Autowired
    private DishFlavorDao dishFlavorDao;
    @Override
    public int add(DishFlavor dishFlavor) {
        return dishFlavorDao.insert(dishFlavor);
    }


    //根据菜品id为条件查询，菜品下面的所有口味
    @Override
    public List<DishFlavor> findByDishId(Long id) {
        //创建条件查询对象
        LambdaQueryWrapper<DishFlavor> qw = new LambdaQueryWrapper<>();
        //设置查询条件
        qw.eq(DishFlavor::getDishId,id);
        //根据设置好的条件进行查询返回，查询的集合
        return dishFlavorDao.selectList(qw);
    }

    @Override
    public int delete(Long id) {
        //创建条件对象
        LambdaQueryWrapper<DishFlavor> qw = new LambdaQueryWrapper<>();
        //设置删除条件
        qw.eq(DishFlavor::getDishId,id);
        //根据条件对象数据库进行删除操作
        return dishFlavorDao.delete(qw);
    }
}
